<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style type="text/css">
    .el-main{
        position: absolute;
        top: 70px;
        bottom: 0px;
        left: 200px;
        right: 10px;
        padding: 0;
    }
    </style>
</head>
<body class="hold-transition skin-purple sidebar-mini">
    <div id="app">
        <el-container>
            <el-header  class="main-header" style="height:70px;">
                <nav class="navbar navbar-static-top" :class=''>
                    <!-- Logo -->
                    <a href="#" class="logo" style="text-align:center">
                        <span class="logo-lg"><img src="../img/logo.png"></span>
                    </a>
                    <div class="right-menu">
                        <span class="help"><i class="fa fa-exclamation-circle" aria-hidden="true"></i>帮助</span>
                        <el-dropdown class="avatar-container right-menu-item" trigger="click">
                            <div class="avatar-wrapper">
                                <img src="../img/user2-160x160.jpg" class="user-avatar">
                                {{username}}
                            </div>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item divided>
                                    <span style="display:block;"  @click="editPassword(username)">修改密码</span>
                                </el-dropdown-item>
                                <el-dropdown-item divided>
                                        <span style="display:block;">
                                            <a href="/logout.do">退出</a>
                                        </span>
                                    </el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </div>
                </nav>
            </el-header>
            <el-container>
                <el-aside width="200px">
                    <el-menu>
                        <el-submenu v-for="menu in menuList" :index="menu.path">
                            <template slot="title">
                                <i class="fa" :class="menu.icon"></i>
                                {{menu.title}}
                            </template>
                            <template v-for="child in menu.children">
                                <el-menu-item :index="child.path">
                                    <a :href="child.linkUrl" target="right">{{child.title}}</a>
                                </el-menu-item>
                            </template>
                        </el-submenu>
                    </el-menu>
                </el-aside>
                <el-container>
                    <iframe name="right" class="el-main" src="report_business.html" width="100%" height="580px" frameborder="0"></iframe>
                </el-container>
            </el-container>
        </el-container>

        <!--新增一个密码弹窗-->
        <div class="add-form">
            <el-dialog title="修改当前用户密码" :visible.sync="dialogFormVisiblePassword">
                <el-form ref="editPasswordform" :model="passwordData" :rules="rules" label-position="right" label-width="100px">
                    <el-row>
                        <el-col :span="20">
                            <el-form-item label="原始密码" prop="oldPassword"><el-input v-model="passwordData.oldPassword" type="password"/></el-form-item></el-col></el-row>
                    <el-row>
                        <el-col :span="20">
                            <el-form-item label="新密码" prop="newPassword"><el-input v-model="passwordData.newPassword" type="password"/></el-form-item></el-col></el-row>

                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisiblePassword = false">取消</el-button>
                    <el-button type="primary" @click="handleEdit()">确定</el-button>
                </div>
            </el-dialog>
        </div>

    </div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script>
    new Vue({
        el: '#app',
        data:{
            username:null,
            menuList:[],
            passwordData:{},
            dialogFormVisiblePassword : false,
            rules: {//校验规则
                oldPassword: [{ required: true, message: '原始密码不能为空', trigger: 'blur' }],
                newPassword: [{ required: true, message: '新密码不能为空', trigger: 'blur' }]
            }
        },
        created:function () {
            // 获取当前登录人的用户名
            axios.get("/user/getUsername.do").then((response)=>{
                // 封装Result(flag,message,data)
                this.username = response.data.data;
            });
            // 获取当前登录人的菜单
            axios.get("/menu/getMenu.do").then((response)=>{
                // 封装Result(flag,message,data)
                this.menuList = response.data.data;
            });
        },
        //方法：
        methods:{
            //编辑密码弹窗：点击修改密码弹窗：
            editPassword(username){
                this.dialogFormVisiblePassword=true;
                this.passwordData={};
                this.passwordData.username=this.username;
            },
            //跳转到登录页面的方法：
            //表单验证通过之后提交：
            handleEdit(){
                this.$refs['editPasswordform'].validate((valid)=>{
                    //如果表单正确，就提交东西：
                    if(valid){
                      var pramas={
                          username:this.passwordData.username,
                          oldPassword:this.passwordData.oldPassword,
                          newPassword:this.passwordData.newPassword
                      }
                      if(this.passwordData.oldPassword===this.passwordData.newPassword){
                          this.$message({
                              type:'warning',
                              message:'您两次输入的密码值相同'
                          })
                      }else {
                          axios.post("/user/updatePassword.do",pramas).then((res)=>{
                              if(res.data.flag){
                                  this.$message({
                                      type:'success',
                                      message:res.data.message+"三秒后退出登录页面"
                                  })
                                  this.dialogFormVisiblePassword=false;
                                 window.setTimeout(function () {
                                 window.location.href="/login.html";
                                 },3000)

                              }else {
                                  this.$message({
                                      type:'error',
                                      message:res.data.message
                                  })
                              }
                          }).cache((error)=>{

                          }).finally(()=>{

                          })

                      }
                    }else {
                        this.$message({
                            type:'error',
                            message:"表单验证有误"
                        })
                    }
                })
            }

        }


    });
    $(function() {
            var wd = 200;
            $(".el-main").css('width', $('body').width() - wd + 'px');
    });
</script>
</html>
